home *** CD-ROM | disk | FTP | other *** search
-
- #include "swar.h"
-
- #define NIL_POINTER 0L
-
- ToolBoxInit()
- {
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MenuBarInit();
- }
-
- InitColors()
- {
- extern RGBColor myGreen, myRed, myBlue, myYellow, myWhite, myBlack, myGray, myOrange, myDkBlue;
-
- myGreen.red = 0;
- myGreen.green = -1;
- myGreen.blue = 0;
- myYellow.red = -1;
- myYellow.green = -1;
- myYellow.blue = 0;
- myRed.red = -1;
- myRed.green = 0;
- myRed.blue = 0;
- myBlue.red = 25000;
- myBlue.green = 55000;
- myBlue.blue = -1;
- myDkBlue.red = 10000;
- myDkBlue.green = 10000;
- myDkBlue.blue = -1;
- myWhite.red = -1;
- myWhite.green = -1;
- myWhite.blue = -1;
- myBlack.red = 0;
- myBlack.green = 0;
- myBlack.blue = 0;
- myGray.red = 20000;
- myGray.green = 20000;
- myGray.blue = 20000;
- myOrange.red = 40000;
- myOrange.green = 25000;
- myOrange.blue = 8000;
- }
-
- MenuBarInit()
- {
- Handle myMenuBar;
- extern MenuHandle gAppleMenu, gFileMenu, gEditMenu;
-
- myMenuBar = GetNewMBar(500);
- SetMenuBar(myMenuBar);
- gFileMenu = GetMHandle(501);
- gEditMenu = GetMHandle(502);
- gAppleMenu = GetMHandle(500);
- if (gAppleMenu)
- AddResMenu(gAppleMenu, 'DRVR');
-
- } /* MenuBarInit() */
-
- LoadSounds()
- {
- extern Handle gNewMatchSoundH;
- extern Handle gShotSoundH;
- extern Handle gBoomSoundH;
- extern Handle gEndorsementSndH;
-
- LoadSound(&gNewMatchSoundH, 501, "\p'snd ' New Level (501)");
- LoadSound(&gShotSoundH, 502, "\p'snd ' Shot (502)");
- LoadSound(&gBoomSoundH, 503, "\p'snd ' Boom (503)");
- AInitSnd();
-
- } /* LoadSounds() */
-
- UnloadSounds()
- {
- extern Handle gNewMatchSoundH;
- extern Handle gShotSoundH;
- extern Handle gBoomSoundH;
- extern Handle gEndorsementSndH;
-
- UnloadSound(gNewMatchSoundH);
- UnloadSound(gShotSoundH);
- UnloadSound(gBoomSoundH);
- AStopSnd();
-
- } /* UnloadSounds() */
-
- CGrafPort *
- PortInit(myRect, depth, portName)
- Rect myRect;
- short depth;
- Str255 portName;
- {
- long bytes;
- Ptr myBits;
- GrafPtr savePort;
- GrafPtr newGrafPtr;
- CGrafPtr newCGrafPtr;
-
- GetPort(&savePort);
- if ((newCGrafPtr = (CGrafPtr)NewPtr(sizeof(CGrafPort))) == NIL_POINTER) {
- ExitAppl();
- } /* if */
- OpenCPort(newCGrafPtr);
- bytes = (((depth * (myRect.right - myRect.left)) + 15) >> 4) << 1;
- myBits = NewPtr(bytes * (myRect.bottom - myRect.top));
- if (depth == 1) {
- newGrafPtr = (GrafPtr) newCGrafPtr;
- (newGrafPtr->portBits).baseAddr = myBits;
- (newGrafPtr->portBits).rowBytes = bytes;
- (newGrafPtr->portBits).bounds = myRect;
- } /* if */
- else {
- (**(*newCGrafPtr).portPixMap).baseAddr = myBits;
- (**(*newCGrafPtr).portPixMap).rowBytes = bytes | 0x8000;
- (**(*newCGrafPtr).portPixMap).bounds = myRect;
- (**(*newCGrafPtr).portPixMap).hRes = 72;
- (**(*newCGrafPtr).portPixMap).vRes = 72;
- (*newCGrafPtr).portRect = myRect;
- } /* else */
-
- // Must set FG and BG pens for black background
- //
- RGBForeColor(&myBlack);
- RGBBackColor(&myBlack);
-
- // Erase entire port
- //
- EraseRect(&myRect);
-
- // restore old port value (game screen)
- //
- SetPort(savePort);
-
- return(newCGrafPtr);
-
- } /* PortInit() */
-
- WindowInit()
- {
- Rect myRect;
- short depth;
- GrafPtr savePort;
- extern CWindowPtr gPictureWindow;
- extern CGrafPort *gOSPtr, *gScrapPtr;
-
- GetPort(&savePort);
- gPictureWindow = (CWindowPtr)GetNewCWindow(500, NIL_POINTER, (WindowPtr) -1L);
- SetPort((GrafPtr)gPictureWindow);
-
- // Must set FG and BG pens for CopyBits to work
- //
- RGBForeColor(&myBlack);
- RGBBackColor(&myWhite);
-
- // Create offscreen port for game playing field
- //
- myRect = gPictureWindow->portRect;
- depth = (**(*gPictureWindow).portPixMap).pixelSize;
- gOSPtr = (CGrafPort *)gPictureWindow;
-
- // Create scrap port containing game pieces
- //
- myRect.top = 0;
- myRect.bottom = 329;
- myRect.left = 0;
- myRect.right = 329;
- if ((gScrapPtr = PortInit(myRect, depth, "\pScrap Port")) == NIL_POINTER) {
- ExitAppl();
- } /* if */
-
- SetPort(savePort);
-
- } /* WindowInit() */
-
- LoadPieces()
- {
- short i, h, s;
- Rect scrapPortRect;
- GrafPtr savePort;
- PicHandle gamePiecePicH;
-
- GetPort(&savePort);
- SetPort((GrafPtr)gScrapPtr);
-
- // Load game pieces, then draw them into the scrap port
- //
- if ((gamePiecePicH = GetPicture(500)) == 0L) {
- ExitAppl();
- } /* if */
- scrapPortRect = (**(gamePiecePicH)).picFrame;
- DrawPicture(gamePiecePicH, &scrapPortRect);
- ReleaseResource((Handle)gamePiecePicH);
-
- SetPort(savePort);
-
- } /* LoadPieces() */
-